﻿/*
 * Created by SharpDevelop.
 * User: PLUS
 * Date: 07.03.2010
 * Time: 17:53
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using FinancialPersonal;
using FinancialPersonal.Entities;
using FinancialPersonal.Logic;

namespace FinancialPersonal.WinForm
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		UserEntity currentUser=null;
		ComboBox tb = new ComboBox();
		PropertyGrid pg =new PropertyGrid();
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			tb.DataSource = GetUserJids();
			Panel panel1 = new Panel();
			
			panel1.Parent = this;
			panel1.Dock = DockStyle.Top;
			panel1.Height = 100;
			Button bt = new Button();
			bt.Top = 0;
			bt.Left=0;
			panel1.Controls.Add(bt);
			bt.Parent = panel1;
			bt.Click += new EventHandler(bt_Click);
			tb.Parent = panel1;
			panel1.Controls.Add(tb);
			tb.Width = 100;
			tb.Top = 0;
			tb.Left = bt.Width+5;
			
			Panel panel2 = new Panel();
			
			panel2.Parent = this;
			panel2.Dock = DockStyle.Fill;
			panel2.Controls.Add(pg);
			pg.Parent = panel2;
			pg.Dock = DockStyle.Fill;
			
			Panel panel3 = new Panel();
			panel3.Parent = this;
			panel3.Dock = DockStyle.Fill;
			panel3.Controls.Add(panel2);
			panel3.Controls.Add(panel1);
			this.Controls.Add(panel3);
			
			pg.Enter += new EventHandler(pg_Click);
		}
		
		string[] GetUserJids()
		{
			List<string> users = new List<string>();
			var entities =  Logic.FinanceLogic.Instance.GetAllUsers();
			foreach(FinancialPersonal.Entities.UserEntity user in 	entities)
			{
				users.Add(user.Jid);
			}
			return users.ToArray();
		}

		void pg_Click(object sender, EventArgs e)
		{
			Logic.FinanceLogic.Instance.StoreUser(currentUser);
		}

		void bt_Click(object sender, EventArgs e)
		{
			
			currentUser = Logic.FinanceLogic.Instance.GetUserByJid(tb.Text);
			
			pg.SelectedObject = currentUser;
			
		}
	}
}
